package com.lgy.controller;

import com.lgy.pojo.Car;
import com.lgy.service.ICarService;
import com.lgy.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/car")
public class CarController {

    @Autowired
    private ICarService carService;

    @RequestMapping("/list")
    @ResponseBody
    public ResultData catList(@RequestParam(value = "brandId", required = false) Integer brandId,
                              @RequestParam(value = "seriesId", required = false) Integer seriesId) {

        if (brandId == null && seriesId == null) {
            return ResultData.error("品牌brandId和车系seriesId不能同时为空!");
        }

        List<Car> carList = carService.selectCarByBrandOrSeries(brandId, seriesId);
        return ResultData.ok(carList);
    }
}
